package com.shanghaionstar.mro;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;

import com.shanghaionstar.R;
import com.shanghaionstar.mro.bean.MrOOperateType;
import com.shanghaionstar.nav.service.AbstractMapActivity;

public abstract class MrOBaseActivity extends AbstractMapActivity {

    public void changeFragment(FragmentManager fragmentManager, Fragment fragment, String tag, boolean isAddBackStack) {
        setCurrentFragmentTag(tag);
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        fragmentTransaction.replace(R.id.fragment_container, fragment, tag);
        fragmentTransaction.addToBackStack(null);
        if (fragmentManager.findFragmentByTag(tag) == null) {
            getLogger().d("Initialize fragment,add fragment to backStack");
            if (isAddBackStack) {
                fragments.add(fragment);
            }
        }
        fragmentTransaction.commitAllowingStateLoss();
    }

    public void changeResultFragment(FragmentManager fragmentManager, Fragment fragment, Class<?> clazz, boolean isAddBackStack) {
        String tag = clazz.getSimpleName();
        changeResultFragment(fragmentManager, fragment, tag, isAddBackStack);
    }

    public void changeResultFragment(FragmentManager fragmentManager, Fragment fragment, String tag, boolean isAddBackStack) {
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        fragmentTransaction.replace(R.id.mro_result_fragment_container, fragment, tag);
        fragmentTransaction.addToBackStack(null);
        fragmentTransaction.commitAllowingStateLoss();
    }

    public abstract void operationType(MrOOperateType mrOOperateType);
}
